package com.mipo.shiro.realm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.junit.Test;
public class DemoCustomRealm {
	@Test
	public void demoCustomRealm(){
	    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-realm.ini");
	    SecurityManager securityManager = factory.getInstance();
	    SecurityUtils.setSecurityManager(securityManager);
	    Subject subject = SecurityUtils.getSubject();
	    UsernamePasswordToken token = new UsernamePasswordToken("admin","123456");
	    try{
	        subject.login(token);
	    }catch (AuthenticationException ex){
	    	
	    }
	    System.out.println(subject.isAuthenticated()); // true
	    subject.logout();
	}
}

